# -*- coding: utf-8 -*-
#!/usr/bin/python

#------------------------------------------------------------------------

## @package     question
## \brief       management of the question
## \author      Pierrick Troadec et Kawtar Hssain
## \date        28/12/2011
## \version     1.2
## \copyright   license BSD

#------------------------------------------------------------------------

#    Importations
#  -----------------

import primitives as prims
from constante import *

import pyglet 

import piece as _piece

import jukebox as _jukebox

#   Fonctions
#  -----------------


##  Lancement de la phase des questions
##@param ex             : position en abscisse du joueur
##@param ez             : position en ordonnee du joueur
##@param batiment       : liste des pièces du bâtiment
##@param key            : état des touches réponses
##@param aventurier     : le joueur
def afficherQuestion(ex,ez, batiment, key, aventurier, jukebox):

    
    num = _piece.numPiece(ex,ez, batiment)
    if num != 99:
        piece = batiment[num]
        prof = piece["prof"]
        

        
        question = pyglet.text.Label(prof["question"],\
                    font_name='Arial',\
                    font_size=25,\
                    width = 500,\
                    color = (0, 0, 0, 255),\
                    bold = True,\
                    multiline=True,\
                    x = 200, y = 260)

        fin1 = pyglet.text.Label(prof["finP"],\
                    font_name='Arial',\
                    font_size=25,\
                    width = 500,\
                    color = (0, 0, 0, 255),\
                    bold = True,\
                    multiline=True,\
                    x = 200, y = 260)
                    
        fin2 = pyglet.text.Label(prof["finM"],\
                    font_name='Arial',\
                    font_size=25,\
                    width = 500,\
                    color = (0, 0, 0, 255),\
                    bold = True,\
                    multiline=True,\
                    x = 200, y = 260)
                    
                    
        
        if prof["pose_une_question"] and not prof["donne_sa_reponse"]:
            prims.afficherImage(position=(0,115,0), dimension = (180,180), texture = prof["texture"], rep=1)
            question.draw()
            prims.afficherImage(position=(0,0,0), dimension = (1100,1200), texture = fond, rep=1)
            aventurier["bloque"] = True
            
            if key in [1,2,3]:
                prof["donne_sa_reponse"] = True
            
        
        if prof["donne_sa_reponse"]:
        

            prof["pose_une_question"] = False
            
            if key == prof["reponse"]:
                prims.afficherImage(position=(0,115,0), dimension = (180,180), texture = prof["texture"], rep=1)
                fin1.draw()
                prims.afficherImage(position=(700,0,0), dimension = (80,80), texture = toucheF, rep=1)
                prims.afficherImage(position=(0,0,0), dimension = (1100,1200), texture = fond, rep=1)
                _piece.ouverture(piece)
                piece["plafond"] = plafond_vert
                prof["fin"] = True
                aventurier["win"] = True
                
            
            else:
                prims.afficherImage(position=(0,115,0), dimension = (180,180), texture = prof["texture"], rep=1)
                fin2.draw()
                prims.afficherImage(position=(700,0,0), dimension = (80,80), texture = toucheF, rep=1)
                prims.afficherImage(position=(0,0,0), dimension = (1100,1200), texture = fond, rep=1)
                _piece.ouverture(piece)
                if not aventurier["win"]:
                    piece["plafond"] = plafond_rouge
                    prof["fin"] = True
                    _jukebox.changerSon(jukebox, fail)
                
            if key == "f":
                prof["donne_sa_reponse"] = False
                prof["pose_une_question"] = False
                aventurier["bloque"] = False
                
        if aventurier["win"] and not prof["donne_sa_reponse"]:
            aventurier["score"] += SCORE_MAX/NOMBRE_DE_PROF
            aventurier["win"] = False
            

    
    
    return 1
                
